package chapter05.exercise;

public class FinalizeTest {

    public static void main(String[] args) {
        Book book = new Book(true);

        book.checkIn();

        new Book(true);

        System.gc();
    }
}

class Book {
    boolean checkOut = false;

    Book(boolean checkOut) {
        this.checkOut = checkOut;
    }

    void checkIn() {
        this.checkOut = false;
    }

    @Override
    protected void finalize() throws Throwable {
        super.finalize();
        if (this.checkOut)
            System.out.println("error: checkOut");
    }
}
